package com.jmebananas.scene;

import com.jme.math.Vector3f;
import com.jme.scene.Controller;
import com.jmebananas.math.FloatController;

/**
 * SpringTranslationController
 * 
 * @author Glenn Powell
 *
 */
public class TranslationController extends Controller {

	private static final long serialVersionUID = 1L;


	private FloatController floatController;
	
	private Vector3f affector;
	
	private Vector3f origin;
	
	private Vector3f destination;
	

	public TranslationController(FloatController floatController, Vector3f translation) {
		this.floatController = floatController;
		setAffector(translation);
	}
	
	public void setAffector(Vector3f translation) {
		this.affector = translation;
		origin = new Vector3f(translation);
		destination = new Vector3f(translation);
	}

	public void translate(Vector3f origin, Vector3f destination) {
		affector.set(origin);
		translate(destination);
	}

	public void translate(Vector3f destination) {
		this.origin.set(affector);
		this.destination.set(destination);
		floatController.setValue(1);
	}

	public void update(float time) {
		if (floatController.update(time)) {
			float position = floatController.getValue();
			affector.set((origin.x - destination.x) * position + destination.x,
					(origin.y - destination.y) * position + destination.y,
					(origin.z - destination.z) * position + destination.z);
		}
	}

}
